//
//  MHShareAppViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/6/6.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHShareAppViewController.h"
#import "MHShareViewAppAlertView.h"
#import "MHCommonCell.h"
#import "MHShareAppViewModel.h"
#import "MHDownLoadH5.h"

@interface MHShareAppViewController ()
@property(nonatomic, strong) MHShareViewAppAlertView *shareAppView;
@property(nonatomic, strong)  MHShareAppViewModel *viewModel;
@end

@implementation MHShareAppViewController
@dynamic viewModel;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)configureCell:(MHCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object
{
    MHCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
    //    id object = groupViewModel.itemViewModels[indexPath.row];
    if (indexPath.row == (groupViewModel.itemViewModels.count - 1)) {
        __weak __typeof(self)weakSelf = self;
        MHCommonItemViewModel *common =   (MHCommonItemViewModel *)object;
        common.operation = ^{
            [[self.viewModel.fetchQrCodeLinkCommond execute:nil] subscribeNext:^(MHDownLoadH5 *dowload) {
//                OSMessage *msg=[[OSMessage alloc] init];
//                msg.title=dowload.title;
//                msg.link = dowload.downUrl;
//                msg.desc = dowload.intro;
//                UIImage *thumbImage = [UIImage imageNamed:@"AppIcon"];
//                NSData *compressData = [thumbImage compressWithLengthLimit:31 *1024];
//                msg.image = compressData;
//                [OpenShare shareToWeixinSession:msg Success:^(OSMessage *message) {
//
//                } Fail:^(OSMessage *message, NSError *error) {
//                }];
                weakSelf.zh_popupController = [zhPopupController new];
                weakSelf.shareAppView.width = weakSelf.view.width * 0.8;
                weakSelf.shareAppView.height = weakSelf.shareAppView.width * (688/612.0);
                [weakSelf.shareAppView.qrCodeImageView yy_setImageWithURL:[NSURL URLWithString:dowload.QRcode] placeholder:MHDefaultAvatar(MHDefaultAvatarTypeDefualt)];
                [weakSelf.zh_popupController presentContentView:weakSelf.shareAppView];
            }];
            
        };
        
    }
    [super configureCell:cell atIndexPath:indexPath withObject:object];
}



-(MHShareViewAppAlertView *)shareAppView
{
    if (!_shareAppView) {
        _shareAppView = [MHShareViewAppAlertView mh_viewFromXib];
    }
    return _shareAppView;
}

@end
